
$(document).ready( function() {
	$(".first-focus").focus();
	$(".datetimepicker").datetimepicker({
		dateFormat: "yy-mm-dd",
		timeFormat: "HH:mm:ss",
		minDateTime: new Date()
	});

	//If anchor points to an accordion tab, expand that tab on page load.
	var url = location.href, idx = url.indexOf("#");
	var hash = idx != -1 ? url.substring(idx+1) : "";

	if (hash.length > 0) {
		$(".collapse#" + hash).collapse("show");
	}

	//Add a choice to the choice edit screen
	$(".addChoiceBtn").click( function(evt) {
		evt.preventDefault();

		var newInput = $("#ChoiceQuestionEditForm input[type='text']").first().parents('li').clone();
		newInput.find('input').val("");
		$("#ChoiceQuestionEditForm .control-group").last().after(newInput);
		$("#ChoiceQuestionEditForm .control-group").last().find('input').focus();
		addClickHandler();
	} );

	//Remove a choice from the choice edit screen
	function addClickHandler() {
		$(".removeChoiceBtn").click( function (evt) {
			evt.preventDefault();
			
			$(this).parents('li').remove();
		} );
	}

	addClickHandler();

	//Enable choice re-ordering
    $( ".sortable" ).sortable();
    $( ".sortable" ).disableSelection();
} );